package com.akkainaction.tool.io.streams.source;

import akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.stream.ActorMaterializer;
import akka.stream.IOResult;
import akka.stream.Materializer;
import akka.stream.javadsl.FileIO;
import akka.stream.javadsl.RunnableGraph;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
import akka.util.ByteString;

import java.nio.file.Paths;
import java.util.concurrent.CompletionStage;

public class TestFileIOSource {

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("sys");
        //materializer主要用来给流分配Actor并驱动其执行
        Materializer materializer = ActorMaterializer.create(system);
        System.out.println(Paths.get("D://demo_in.txt").toUri());
        Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromPath(Paths.get("D://demo_in.txt"));
        source.runForeach(System.out::println,materializer);
        //        Sink<ByteString, CompletionStage<Done>> sink = Sink.foreach(System.out::println);
//        RunnableGraph<CompletionStage<IOResult>> graph = source.to(sink);
//        graph.run(materializer);
    }
}
